home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / util / cdity / ModeProSrc.lha / Daemon / MPReadArgs.c < prev    next >
C/C++ Source or Header  |  1998-12-21  |  7KB  |  223 lines

  1. #include <proto/dos.h>
  2. #include "MP.h"
  3.  
  4. extern struct MPSem *MPSem;
  5. extern UBYTE  *Hotkey,Popup;
  6. extern BYTE   Priority;
  7. extern STRPTR PrefsPath;
  8. extern ULONG  WBPromotable;
  9. ULONG CenterAll;
  10.  
  11. BOOL    GetReadArgs(void);
  12. BOOL    RAYesNo(STRPTR Str, BOOL DefVal);
  13. ULONG   RAInt(ULONG *Val,ULONG DefVal);
  14. STRPTR  RAString(STRPTR Str, STRPTR DefVal);
  15. BOOL    GetToolTypes(int argc, char **argv);
  16.  
  17.  
  18. struct RDArgs *RArgs=NULL;
  19.  
  20. UBYTE DefPrefsPath[]="sys:prefs/ModeProPrefs";
  21.  
  22. UBYTE RATemplate[]= "CX_PRIORITY/N/K,"
  23.                     "CX_POPKEY/K,"
  24.                     "CX_POPUP/K,"
  25.                     "PCMD=PREFSCOMMAND/K,"
  26.                     "WBPROMOTABLE/S,"
  27.                     "DEBUG/S";//                                                                       (4.62.1)
  28. //                   "NLM=NEWLOOKMENUS/S,CAH=CENTERALLHORZ/S,CAV=CENTERALLVERT/S,"
  29. //                   "CPROG=CATCH_NEWPROGRAMS/S,CSCR=CATCH_NEWSCREENS/S,CPOP=CATCH_POPUP/S,"
  30. //                   ",DEBUG/S";
  31.  
  32. #define RA_CX_PRIORITY 0
  33. #define RA_CX_POPKEY   1
  34. #define RA_CX_POPUP    2
  35. #define RA_PREFS       3
  36. #define RA_WBABLE      4
  37. #define RA_DEBUG       5//                                                                             (4.62.2)
  38.  
  39. LONG RAResults[6]={0};//                                                                               (4.62.3)
  40.  
  41. /*
  42. #define RA_NLM         3
  43. #define RA_CAH         4
  44. #define RA_CAV         5
  45. #define RA_CPROG       6
  46. #define RA_CSCR        7
  47. #define RA_CPOP        8
  48. #define RA_DEBUG       10
  49. */
  50.  
  51. WORD    ArgMode;
  52. struct DiskObject *MPIcon;
  53.  
  54.  
  55. BOOL GetArgs(int argc, char **argv)
  56. {
  57.   UBYTE path[512];
  58.   BPTR lock;
  59.   
  60.   ArgMode=min(argc,2);
  61.   WBPromotable=0;
  62.  
  63.   switch(ArgMode)
  64.   {
  65.     case 0:
  66.       return(GetToolTypes(argc,argv));
  67.       break;
  68.     case 1:
  69.       {//                                                                                              (4.61.2)
  70.         char pname[256];//                                                                             (4.61.2)
  71. //                                                                                                     (4.61.2)
  72.         if(GetProgramName(pname,256))//                                                                (4.61.2)
  73.         {//                                                                                            (4.61.2)
  74.           if(lock=GetProgramDir())//                                                                   (4.61.2)
  75.           {//                                                                                          (4.61.2)
  76.             if(NameFromLock(lock,path,512))//                                                          (4.61.2)
  77.             {//                                                                                        (4.61.2)
  78.               if(AddPart(path,pname,512))//                                                            (4.61.2)
  79.               {//                                                                                      (4.61.2)
  80.                 if(MPIcon=GetDiskObject(path))//                                                       (4.61.2)
  81.                 {//                                                                                    (4.61.2)
  82.                   LONG l;//                                                                            (4.61.2)
  83.                   //                                                                                   (4.61.2)
  84.                   for(l=0;MPIcon->do_ToolTypes[l];l++);//                                              (4.61.2)
  85.                   //                                                                                   (4.61.2)
  86.                   return(GetToolTypes(l,MPIcon->do_ToolTypes));//                                      (4.61.2)
  87.                 }//                                                                                    (4.61.2)
  88.               }//                                                                                      (4.61.2)
  89.             }//                                                                                        (4.61.2)
  90.           }//                                                                                          (4.61.2)
  91.         }//                                                                                            (4.61.2)
  92.       }//                                                                                              (4.61.2)
  93.       return(0);
  94.     case 2:
  95.       return(GetReadArgs());
  96.   }
  97. }
  98.  
  99.  
  100. void CleanupArgs(int argc)
  101. {
  102.   switch(ArgMode)
  103.   {
  104.     case 0:
  105.       ArgArrayDone();
  106.       break;
  107.     case 1:
  108.       ArgArrayDone();
  109.       FreeDiskObject(MPIcon);
  110.       break;
  111.     case 2:
  112.       FreeArgs(RArgs);
  113.       break;
  114.   }
  115. }
  116.  
  117.  
  118. /*
  119. BOOL GetArgs(int argc, char **argv)
  120. {
  121.   BOOL rv;
  122.   
  123.   if(argc) //cli
  124.     rv=GetReadArgs();
  125.   else
  126.     rv=GetToolTypes(argc,argv);
  127.     
  128.   return(rv);
  129. }
  130.  
  131. void CleanupArgs(int argc)
  132. {
  133.   if(argc)
  134.   {
  135.     if(RArgs)
  136.       FreeArgs(RArgs);
  137.   }
  138.   else
  139.   {
  140.     ArgArrayDone();
  141.   }
  142. }
  143. */
  144.  
  145. BOOL GetReadArgs(void)
  146. {
  147.   if(RArgs=ReadArgs(RATemplate,RAResults,0))
  148.   {
  149.     Hotkey      =RAString((STRPTR) RAResults[RA_CX_POPKEY],   Hotkey);
  150.     Popup       =RAYesNo ((STRPTR) RAResults[RA_CX_POPUP],    Popup);
  151.     Priority    =RAInt   ((ULONG *)RAResults[RA_CX_PRIORITY], Priority);  
  152. //    MPSem->EnabledNLM    =RAResults[RA_NLM];
  153. //    MPSem->CatchPrograms =RAResults[RA_CPROG];
  154. //    MPSem->CatchScreens  =RAResults[RA_CSCR];
  155. //    MPSem->CatchPopup    =RAResults[RA_CPOP];
  156. //    MPSem->CenterAll     =(RAResults[RA_CAH]?1:0) + (RAResults[RA_CAV]?2:0 );
  157.     PrefsPath   =RAString((STRPTR)RAResults[RA_PREFS],DefPrefsPath);
  158.     WBPromotable=RAResults[RA_WBABLE];
  159.     MPSem->Debug         =RAResults[RA_DEBUG];//                                                       (4.62.4)
  160.     
  161.     return(TRUE);
  162.   }
  163.   else
  164.     PrintFault(IoErr(),0);
  165.   return(FALSE);
  166. }
  167.  
  168. BOOL RAYesNo(STRPTR Str, BOOL DefVal)
  169. {
  170.   if(Str)
  171.   {
  172.     switch(*Str)
  173.     {
  174.       case 'T':
  175.       case 't':
  176.       case 'Y':
  177.       case 'y':
  178.         return(~0);
  179.       case 'F':
  180.       case 'f':
  181.       case 'N':
  182.       case 'n':
  183.         return(0);
  184.     }
  185.   }
  186.   return(DefVal);
  187. }
  188.  
  189. ULONG RAInt(ULONG *Val,ULONG DefVal)
  190. {
  191.   if(Val)
  192.     return(*Val);
  193.   return(DefVal);
  194. }
  195.  
  196. STRPTR RAString(STRPTR Str, STRPTR DefVal)
  197. {
  198.   if(Str)
  199.     return(Str);
  200.   return(DefVal);
  201. }    
  202.  
  203. BOOL GetToolTypes(int argc, char **argv)
  204. {
  205.   UBYTE **ttypes;
  206.  
  207.   ttypes  =ArgArrayInit(argc,argv);
  208.  
  209.   Hotkey  =ArgString(ttypes,(UBYTE *)"CX_POPKEY",       Hotkey);
  210.   Priority=ArgInt   (ttypes,(UBYTE *)"CX_PRIORITY",     0);
  211.   Popup   =ArgYesNo (ttypes,(UBYTE *)"CX_POPUP",        TRUE);
  212. //  MPSem->EnabledNLM=ArgYesNo(ttypes,(UBYTE *)"NEWLOOKMENUS",FALSE);
  213. //  MPSem->CatchPrograms =ArgYesNo (ttypes,(UBYTE *)"CATCH_NEWPROGRAMS",FALSE);
  214. //  MPSem->CatchScreens  =ArgYesNo (ttypes,(UBYTE *)"CATCH_NEWSCREENS",FALSE);
  215. //  MPSem->CatchPopup    =ArgYesNo (ttypes,(UBYTE *)"CATCH_POPUP",FALSE);
  216.   PrefsPath   =ArgString    (ttypes,(UBYTE *)"PREFSCOMMAND",    DefPrefsPath);
  217.   WBPromotable=(ULONG)ArgString(ttypes,(UBYTE *)"WBPROMOTABLE",       0);
  218.   MPSem->Debug =ArgYesNo (ttypes,(UBYTE *)"DEBUG",FALSE);//                                            (4.62.5)
  219. //  MPSem->CenterAll     =(ArgYesNo (ttypes,(UBYTE *)"CENTERALLHORZ",FALSE)?1:0) |
  220. //                        (ArgYesNo (ttypes,(UBYTE *)"CENTERALLVERT",FALSE)?2:0 );
  221.   return((BOOL)ttypes);
  222. }
  223.